package com.pb.wkflow.core.camunda.bpmn.instanceImpl;

import com.pb.wkflow.core.camunda.bpmn.instance.Participants;
import com.pb.wkflow.core.camunda.bpmn.instance.UserParticipant;
import com.pb.wkflow.core.camunda.bpmn.instance.VoteWork;
import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.model.bpmn.impl.instance.BpmnModelElementInstanceImpl;
import org.camunda.bpm.model.xml.ModelBuilder;
import org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext;
import org.camunda.bpm.model.xml.type.ModelElementTypeBuilder;
import org.camunda.bpm.model.xml.type.attribute.Attribute;

import static org.camunda.bpm.model.bpmn.impl.BpmnModelConstants.CAMUNDA_NS;

/**
 *
 * @author 苗益辉
 * @date 2022/5/17 19:09
 */
@Slf4j
public class VoteWorkImpl extends BpmnModelElementInstanceImpl implements VoteWork {

    /** 参与者分配策略 */
    protected static Attribute<String> allocationAttribute;
    /** 是否串行 */
    protected static Attribute<String> isSequentialAttribute;
    /** 完成规则 */
    protected static Attribute<String> finishRuleAttribute;
    /** 要求同意个数 */
    protected static Attribute<String> passNumAttribute;
    /** 同意百分比 */
    protected static Attribute<String> passPercentAttribute;

    public VoteWorkImpl(ModelTypeInstanceContext instanceContext) {
        super(instanceContext);
    }

    public static void registerType(ModelBuilder modelBuilder) {
        log.info("注册自定义会签 VoteWork");
        ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(VoteWork.class, "voteWork")
                .namespaceUri(CAMUNDA_NS)
                .instanceProvider(new ModelElementTypeBuilder.ModelTypeInstanceProvider<VoteWork>() {
                    @Override
                    public VoteWork newInstance(ModelTypeInstanceContext instanceContext) {
                        return new VoteWorkImpl(instanceContext);
                    }
                });

        allocationAttribute = typeBuilder.stringAttribute("allocation").namespace(CAMUNDA_NS).build();
        isSequentialAttribute = typeBuilder.stringAttribute("isSequential").namespace(CAMUNDA_NS).build();
        finishRuleAttribute = typeBuilder.stringAttribute("finishRule").namespace(CAMUNDA_NS).build();
        passNumAttribute = typeBuilder.stringAttribute("passNum").namespace(CAMUNDA_NS).build();
        passPercentAttribute = typeBuilder.stringAttribute("passPercent").namespace(CAMUNDA_NS).build();
        typeBuilder.build();
    }

    @Override
    public String getAllocation() {
        return allocationAttribute.getValue(this);
    }

    @Override
    public void setAllocation(String allocation) {
        allocationAttribute.setValue(this,allocation);
    }

    @Override
    public String getIsSequential() {
        return isSequentialAttribute.getValue(this);
    }

    @Override
    public void setIsSequential(String isSequential) {
        isSequentialAttribute.setValue(this,isSequential);
    }

    @Override
    public String getFinishRule() {
        return finishRuleAttribute.getValue(this);
    }

    @Override
    public void setFinishRule(String finishRule) {
        finishRuleAttribute.setValue(this,finishRule);
    }

    @Override
    public String getPassNum() {
        return passNumAttribute.getValue(this);
    }

    @Override
    public void setPassNum(String passNum) {
        passNumAttribute.setValue(this,passNum);
    }

    @Override
    public String getPassPercent() {
        return passPercentAttribute.getValue(this);
    }

    @Override
    public void setPassPercent(String passPercent) {
        passPercentAttribute.setValue(this,passPercent);
    }
}